﻿using LeafTransmission.Utils;
using System.Collections;
using System.Net;

namespace LeafTransmission.Entity
{

    /// <summary>
    /// 用户实体类
    /// Username默认就是计算机名
    /// </summary>
    public class UserInfoEntity
    {
        // TODO://注意这里需要先将 本机名写入
        public string Username { get; set; } = Dns.GetHostName();
        // 工作组
        public ArrayList Workgroup { get; set; } = new ArrayList();
        public string? Email { get; set; }
        public ArrayList IpAddressArr { get; set; }
        public UserInfoEntity()
        {
            /*var userInfoConfig = XMLDocumentUtil.ReadConfigXML(XMLDocumentUtil.USER_INFO_CONFIG_XML);
            foreach (var item in userInfoConfig)
            {
                switch (item.Key)
                {
                    case "Username":
                        Username = item.Value;
                        break;
                    case "Email":
                        Email = item.Value;
                        break;
                    case "Workgroup":
                        // TODO:// 这里需要重构配置文件, 工作组应该有多个
                        Workgroup.Clear();
                        Workgroup.Add(item.Value);
                        break;
                }
            }*/

            IPHostEntry ipEntry = Dns.GetHostEntry(Dns.GetHostName());
            IPAddress[] ipAddr = ipEntry.AddressList;
            IpAddressArr = new ArrayList();
            for (int i = 0; i < ipAddr.Length; i++)
            {
                if (ipAddr[i].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    IpAddressArr.Add(ipAddr[i]);
                }
            }
        }
        public UserInfoEntity(string username, ArrayList workgroup, string email, ArrayList ipAddressArr)
        {
            Username = username;
            Workgroup = workgroup;
            Email = email;
            IpAddressArr = ipAddressArr;
        }

    }
}